package cmu.mobile.lab;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RadioButton;

public class ItemInfo extends Activity {
	//static final int GET_ADVICE = 2334;
	//static final int SUGGEST = 2335;
	//static final int SELECT_FRIENDS = 2336;
	//private int mode;
	Intent result;
	EditText itemStore;
	EditText itemSize;
	//EditText itemPrice;
	


	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_iteminfo);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		final Bundle extras = getIntent().getExtras();
		result = new Intent();

		itemStore = (EditText)findViewById(R.id.StoreBox);
		//itemPrice = (EditText)findViewById(R.id.PriceBox);
		itemSize = (EditText)findViewById(R.id.SizeBox);
		
		// back button
		findViewById(R.id.BackButton).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				setResult(Activity.RESULT_CANCELED);
				finish();
			}
		});
		
		//delete text when store box selected
		findViewById(R.id.StoreBox).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
					itemStore.setText("");
			}
		});
		
		/*//delete text when price box selected
		findViewById(R.id.PriceBox).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
					itemPrice.setText("");
			}
		});*/
		
		//delete text when size box selected
		findViewById(R.id.SizeBox).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
					itemSize.setText("");
			}
		});

		/*OnClickListener radioListener = new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				int buttonID = ((RadioButton) v).getId();
				if (R.id.GetAdviceCheck == buttonID)
					mode = GET_ADVICE;
				else if (R.id.SuggestCheck == buttonID)
					mode = SUGGEST;
			}
		};
		
		findViewById(R.id.GetAdviceCheck).setOnClickListener(radioListener);
		findViewById(R.id.SuggestCheck).setOnClickListener(radioListener);
		findViewById(R.id.SelectFriendBox).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent friendsIntent = new Intent(ItemInfo.this, 
						FriendsList.class);
				// get list of friends back
				startActivityForResult(friendsIntent, SELECT_FRIENDS);
			}
		});*/
		
		
		findViewById(R.id.SubmitButton).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// store info and save it,
				// then start sms-in
				String store = ((EditText)findViewById(R.id.StoreBox))
					.getText().toString();
				String price = ((EditText)findViewById(R.id.PriceBox))
					.getText().toString();
				String size = ((EditText)findViewById(R.id.SizeBox))
					.getText().toString();
				Intent sendMessageIntent = new Intent(ItemInfo.this, SMS.class);
				sendMessageIntent.putExtra("store", store);
				sendMessageIntent.putExtra("price", price);
				sendMessageIntent.putExtra("size", size);
				//sendMessageIntent.putExtra("mode", mode);
				
				// get info from additem
				
				sendMessageIntent.putExtra("imagePath", 
						extras.getString("imagePath"));
				sendMessageIntent.putExtra("ownerid", extras
						.getString("ownerid"));

						
				// Move this to SMS, on return from sms screen. 
				// Add the item to the database
			
		//		mDbHelper = new Database(ItemInfo.this);
		//        mDbHelper.open();
			
		//        //Integer _item, String owner, String friend, String store, Integer price, String message, String image
		//		mDbHelper.close();
				
				// TODO: get friends numbers
				String phoneNumbers = ((EditText) findViewById(R.id.PhoneBox))
					.getText().toString();
				sendMessageIntent.putExtra("phoneNumbers", phoneNumbers);
				
				startActivity(sendMessageIntent);
			}
		});
	}
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		
	}

}
